package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import model.User;
import model.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Title: findAuthor
 * @Author 郑雨杭
 * @Package servlet
 * @Date 2024/7/30 13:40
 * @description:
 */
@WebServlet("/findAuthor")
public class findAuthor extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int blogId = Integer.parseInt(req.getParameter("blogId"));
        UserDao userDao = new UserDao();
        User user = userDao.findByBlongId(blogId);
        user.setPassword("");
        resp.setContentType("application/json;charset=utf8");
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(user);
        resp.getWriter().write(s);
    }
}
